package org.slf4j.impl;

import java.io.FileWriter;
import java.io.IOException;

class XtraTinyLoggerFileAppender extends XtraTinyLoggerAppender {
	private static final String LOG_FILENAME = "all.log";

	private FileWriter fileWriter;

	public XtraTinyLoggerFileAppender()
			throws XtraTinyLoggerInstantiationException {
		super();
		try {
			fileWriter = new FileWriter(LOG_FILENAME);
		} catch (IOException e) {
			throw new XtraTinyLoggerInstantiationException("Unable to initialize file appender.");
		}
	}

	@Override
	public void processMessage(String msg) {
		try {
			fileWriter.write(msg + "\n");
		} catch (IOException e) {
			// no sense to log logger's error
		}
	}

	@Override
	protected void shutdown() {
		try {
			fileWriter.close();
			System.out.println("XtraTinyLoggerFileAppender is shutdown.");
		} catch (IOException e) {
			// no sense to log logger's error
		}
	}
}